package com.dream.keigezhushou.Activity.acty.personal;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyAttentionActivity extends AppCompatActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_attention)
    ListView lvAttention;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_attention);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("关注");
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        lvAttention.setDivider(null);
        //ListView创建适配器
        lvAttention.setAdapter(new AttenAdapter(this));
    }

    public class AttenAdapter extends BaseAdapter {
        private Context mContext;
        int c = 8;
        public AttenAdapter(Context context) {
            this.mContext = context;
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder mHolder = null;
            if (convertView == null){

                convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_attention_item,null);
                mHolder = new ViewHolder();
                mHolder.layoutKind = (LinearLayout) convertView.findViewById(R.id.ll_attention_kind2);
                mHolder.ivKind = (ImageView) convertView.findViewById(R.id.iv_attention_kind1);

                convertView.setTag(mHolder);
            }else {
                mHolder = (ViewHolder)convertView.getTag();
            }

            if (position > 0 && position % 3 == 0){

                mHolder.layoutKind.setVisibility(View.VISIBLE);
                mHolder.ivKind.setVisibility(View.GONE);
            }else {
                mHolder.ivKind.setVisibility(View.VISIBLE);
                mHolder.layoutKind.setVisibility(View.GONE);
            }
            return convertView;
        }

        class ViewHolder{

            LinearLayout layoutKind;
            ImageView ivKind;

        }
    }
}
